package ru.st.selenium.applogic2;

import static org.junit.Assert.assertTrue;
import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import ru.st.selenium.applogic.FilmHelper;
import ru.st.selenium.model.Film;
import ru.st.selenium.pages.MovieViewPage;

public class FilmHelper2 extends DriverBasedHelper implements FilmHelper {

  public FilmHelper2(ApplicationManager2 manager) {
    super(manager.getWebDriver());
  }

  @Override
  public void createFilm(Film film) {
    pages.internalPage.clickHomePage().ensurePageLoaded();
    pages.homePage
    	.clickAddMovieButton()
    	.setTitleField(film.getTitle())
    	.setYearField(film.getYear())
    	.clickSubmitButton();
  }

  @Override
  public void deleteFilm() {
	  pages.homePage.ensurePageLoaded();
	  pages.homePage.getFirstFilm().ensurePageLoaded();
	  pages.movieViewPage.clickRemoveMovieButton();
	  wait.until(alertIsPresent()).accept();
  }

  @Override
  public List<Film> search(String title) {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public boolean isCreatedFilm(Film film) {
	  return pages.movieViewPage.getTitleHeader().contains(film.getTitle());
  }

  @Override
  public boolean isNotCreatedFilm() {
	// TODO Auto-generated method stub
	return pages.addMoviePage.getValidationYear() != null;
  }

}
